<%@ page import="java.util.List" %>
<%@ page import="com.game.GameDAO" %>
<%@ page import="com.game.Game" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>游戏商店 - 首页</title>
    <style>a{TEXT-DECORATION:none}</style>
</head>
<body>
<div style="float: left; width: 20%;">
    <h2>导航</h2>
    <ul>
        <li><a href="index.jsp">首页</a></li>
        <li><a href="cart.jsp">购物车</a></li>
    </ul>
</div>

<div style="float: left; width: 60%;">
    <h2>TGA最佳游戏</h2>
    <%
        GameDAO gameDAO = new GameDAO();
        List<Game> games = gameDAO.getAllGames();
        for (Game game : games) {
    %>
    <div>
        <span><%= game.getName() %></span>
        <span>￥<%= game.getPrice() %></span>
        <form action="cart" method="post">
            <input type="hidden" name="gameId" value="<%= game.getId() %>">
            <input type="hidden" name="action" value="add">
            <input type="submit" value="加入购物车">
        </form>
    </div>
    <% } %>
</div>

<div style="float: left; width: 20%;">
    <h2>用户中心</h2>
    <% if (session.getAttribute("username") == null) { %>
    <a href="login.jsp">登录</a>
    <a href="register.jsp">注册</a>
    <% } else { %>
    欢迎 <%= session.getAttribute("username") %><br>
    <p><a href="login.jsp" >退出</a></p>
    <% } %>
</div>
</body>
</html>